package test;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2021-04-23
 * Time: 14:26
 */
public class GiftVoucher {
    public static int nextID = 0;

    private int value;
    private String greeting;
    private int voucherID;
    private String recipient;

    public GiftVoucher(int value, String recipient) {
        this.voucherID = nextID++;
        this.value = value;
        this.recipient = recipient;
    }

    public boolean deductValue(int amount) {
        if (amount < 0 || amount > value) {
            return false;
        }
        value -= amount;
        return true;
    }

    public boolean hasEnoughFounds(int amount) {
        return value >= amount;
    }

    @Override
    public String toString() {
        String message = "Voucher ID: " + voucherID + ", $" + value + ", TO: " + recipient ;
        if (greeting != null) {
            message += ", " + greeting;
        }
        return message;
    }

    public static void setNextID(int nextID) {
        GiftVoucher.nextID = nextID;
    }

    public static int getNextID() {
        return nextID;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getGreeting() {
        return greeting;
    }

    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }

    public int getVoucherID() {
        return voucherID;
    }

    public void setVoucherID(int voucherID) {
        this.voucherID = voucherID;
    }

    public String getRecipient() {
        return recipient;
    }

    public void setRecipient(String recipient) {
        this.recipient = recipient;
    }

    public static void main(String[] args) {
        GiftVoucher.setNextID(345);
        GiftVoucher v = new GiftVoucher(250, "Richard");
        v.setGreeting("Happy Birthday");
        System.out.println(v);

        System.out.println(v.deductValue(-300));
        System.out.println(v);
        System.out.println(v.deductValue(300));
        System.out.println(v);
        System.out.println(v.deductValue(150));
        System.out.println(v);
        System.out.println(v.hasEnoughFounds(200));

        GiftVoucher v2 = new GiftVoucher(50, "Peter");
        System.out.println(v2);

    }
}
